package polsense.filemerger;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.zip.CRC32;

import org.apache.commons.io.FileUtils;

/* FileScanner.java
 * Created on Oct 12, 2005
 * Copyright 2005 Pablo J. Lopez
 */

/**
 * @author Pablo J. Lopez
 */
public class FileCounter implements Runnable {

	private String[] extensions;
	private File directory;
	private boolean finished = false;
        private int count = 0;
        private long totalSize = 0;
        private boolean recursive = false;
	
	
	
	/**
	 * @param directory
	 * @param sink
	 * @param extensions
	 */
	public FileCounter(File directory, String[] extensions, boolean recursive) {
		super();
		// TODO Auto-generated constructor stub
		this.setDirectory(directory);
		this.setRecursive(recursive);
		this.setExtensions(extensions);
	}

	

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		count();
                
	}

        public void count(){
          
            Collection a = FileUtils.listFiles(getDirectory(), getExtensions(), isRecursive());
		
               setCount(a.size());
               
               for (Iterator it = a.iterator(); it.hasNext();) {
                   File elem = (File) it.next();
                  setTotalSize(getTotalSize() + elem.length());
               }
        
        }
        
        
        


	/**
	 * @return Returns the finished.
	 */
	public boolean isFinished() {
		return finished;
	}

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String[] getExtensions() {
        return extensions;
    }

    public void setExtensions(String[] extensions) {
        this.extensions = extensions;
    }

    public File getDirectory() {
        return directory;
    }

    public void setDirectory(File directory) {
        this.directory = directory;
    }

    public void setFinished(boolean finished) {
        this.finished = finished;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public boolean isRecursive() {
        return recursive;
    }

    public void setRecursive(boolean recursive) {
        this.recursive = recursive;
    }



	
	

}
